package com.fount4j.generator.config;

import java.util.Map;

/**
 * 配置项辅助类
 *
 * @author Morven 2016/12/22
 */
public class PropertyHolder {
    /** 其他配置 */
    protected Map<String, Object> properties;

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }

    public Object getProperty(String key) {
        return properties.get(key);
    }

    public String getString(String key) {
        Object o = properties.get(key);
        if (o == null) {
            return null;
        }
        return o.toString();
    }

    public String getString(String key, String defValue) {
        String s = getString(key);
        if (s == null) {
            return defValue;
        }
        return s;
    }

    public Integer getInteger(String key) {
        Object o = properties.get(key);
        if (o == null) {
            return null;
        } else if (o instanceof Integer) {
            return (Integer) o;
        }
        return Integer.parseInt(o.toString());
    }

    public Integer getInteger(String key, Integer defVal) {
        Integer val = getInteger(key);
        if (val == null) {
            return defVal;
        }
        return val;
    }

    public Boolean getBoolean(String key) {
        Object o = properties.get(key);
        if (o == null) {
            return null;
        } else if (o instanceof Boolean) {
            return (Boolean) o;
        }
        return Boolean.parseBoolean(o.toString());
    }

}
